"""
    acquire 上锁      无参数     无返回
    release 开锁      无参数     无返回

    任务加锁-释放锁，保证任务只能有一个进程执行任务
"""
import multiprocessing
import os
import time
from multiprocessing import Process, Manager

def work(count, lock: multiprocessing.Lock):
    lock.acquire()
    try:
        print('count=%s, pid=%s' %(count, os.getpid()))
        time.sleep(1)
    except:
        pass
    finally:
        lock.release()
    return 'count=%s, pid=%s' %(count, os.getpid())


if __name__ == '__main__':
    pool = multiprocessing.Pool(5)
    manager = Manager()
    lock = manager.Lock()
    for i in range(20):
        result = pool.apply_async(work, args=(i, lock))

    pool.close()
    pool.join()

